<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META content="text/html; charset=ISO-8859-2" http-equiv="content-type">
<meta name="robots" content="index,follow">
<META NAME="Keywords" CONTENT="binary, hex, 32-bit unsigned integer, conversion">
<meta name="viewport" content="width=device-width, initial-scale=1">
<META NAME="Author" CONTENT="Tomasz Ostrowski">
<META name="description" content="Binary - 32-bit hex conversion">  
<link rel="stylesheet" type="text/css" media="only screen and (max-width: 959px)" href="./css/mobile.css" />
<link rel="stylesheet" type="text/css" media="only screen and (min-width: 960px)" href="./css/main.css" />
<script type="text/javascript" src="./js/tree.js"></script>


<script src="./js/jquery-2.1.3.min.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="./css/jquery-eu-cookie-law-popup.css"/>
<script src="./js/jquery-eu-cookie-law-popup-en.js"></script> -->

<title>Binary - 32-bit hex conversion</title>  
</head>
<body class="eupopup eupopup-bottomleft eupopup-style-compact">

<div id="wrap">
<div id="header">
<div id="header_l">
  <a href="../index.htm">erma0.cn</a>
</div>
<div id="header_r"><A HREF="./bin_to_32bit_hex.htm" TARGET="_self"><strong>ENGLISH VERSION</strong></A><br><A HREF="./bin_to_32bit_hex.php?lang=pl" TARGET="_self"><strong>WERSJA POLSKA</strong></A></div>      
</div>

<a href="../bot-trap/">
  <img src="./images/pixel.gif" border="0" alt=" " width="1" height="1">
</a>
     

<script type="text/javascript">
//<!--
      function pad(num, size) {
        var s = "0000000" + num;
        return s.substr(s.length-size);
      }

      function binChange() {
        //var output = createHtmlList(document.frmConvert.ed_input.value);
        //document.frmConvert.ed_output.value = output;
        var frm = document.frmConvert;
        var val = 0;
        if (frm.chbBit31.checked)
          val += (1<<31)>>>0;
        if (frm.chbBit30.checked)
          val += (1<<30)>>>0;
        if (frm.chbBit29.checked)
          val += (1<<29)>>>0;
        if (frm.chbBit28.checked)
          val += (1<<28)>>>0;
        if (frm.chbBit27.checked)
          val += (1<<27)>>>0;
        if (frm.chbBit26.checked)
          val += (1<<26)>>>0;
        if (frm.chbBit25.checked)
          val += (1<<25)>>>0;
        if (frm.chbBit24.checked)
          val += (1<<24)>>>0;
        if (frm.chbBit23.checked)
          val += (1<<23)>>>0;
        if (frm.chbBit22.checked)
          val += (1<<22)>>>0;
        if (frm.chbBit21.checked)
          val += (1<<21)>>>0;
        if (frm.chbBit20.checked)
          val += (1<<20)>>>0;
        if (frm.chbBit19.checked)
          val += (1<<19)>>>0;
        if (frm.chbBit18.checked)
          val += (1<<18)>>>0;
        if (frm.chbBit17.checked)
          val += (1<<17)>>>0;
        if (frm.chbBit16.checked)
          val += (1<<16)>>>0;
        if (frm.chbBit15.checked)
          val += (1<<15)>>>0;
        if (frm.chbBit14.checked)
          val += (1<<14)>>>0;
        if (frm.chbBit13.checked)
          val += (1<<13)>>>0;
        if (frm.chbBit12.checked)
          val += (1<<12)>>>0;
        if (frm.chbBit11.checked)
          val += (1<<11)>>>0;
        if (frm.chbBit10.checked)
          val += (1<<10)>>>0;
        if (frm.chbBit9.checked)
          val += (1<<9)>>>0;
        if (frm.chbBit8.checked)
          val += (1<<8)>>>0;
        if (frm.chbBit7.checked)
          val += (1<<7)>>>0;
        if (frm.chbBit6.checked)
          val += (1<<6)>>>0;
        if (frm.chbBit5.checked)
          val += (1<<5)>>>0;
        if (frm.chbBit4.checked)
          val += (1<<4)>>>0;
        if (frm.chbBit3.checked)
          val += (1<<3)>>>0;
        if (frm.chbBit2.checked)
          val += (1<<2)>>>0;
        if (frm.chbBit1.checked)
          val += (1<<1)>>>0;
        if (frm.chbBit0.checked)
          val += (1<<0)>>>0;
        frm.hex.value = "0x" + pad(val.toString(16), 8);                                 
      }

      function hexChange() {
        var frm = document.frmConvert;        
        var num = parseInt(frm.hex.value, 16);

        if (num < 0 || num > 0xFFFFFFFF) {
          alert("Number out of unsigned 32-bit range!");
        }

        frm.chbBit31.checked = num & (1<<31);
        frm.chbBit30.checked = num & (1<<30);
        frm.chbBit29.checked = num & (1<<29);
        frm.chbBit28.checked = num & (1<<28);
        frm.chbBit27.checked = num & (1<<27);
        frm.chbBit26.checked = num & (1<<26);
        frm.chbBit25.checked = num & (1<<25);
        frm.chbBit24.checked = num & (1<<24);
        frm.chbBit23.checked = num & (1<<23);
        frm.chbBit22.checked = num & (1<<22);
        frm.chbBit21.checked = num & (1<<21);
        frm.chbBit20.checked = num & (1<<20);
        frm.chbBit19.checked = num & (1<<19);
        frm.chbBit18.checked = num & (1<<18);
        frm.chbBit17.checked = num & (1<<17);
        frm.chbBit16.checked = num & (1<<16);
        frm.chbBit15.checked = num & (1<<15);
        frm.chbBit14.checked = num & (1<<14);
        frm.chbBit13.checked = num & (1<<13);
        frm.chbBit12.checked = num & (1<<12);
        frm.chbBit11.checked = num & (1<<11);
        frm.chbBit10.checked = num & (1<<10);
        frm.chbBit9.checked = num & (1<<9);
        frm.chbBit8.checked = num & (1<<8);
        frm.chbBit7.checked = num & (1<<7);
        frm.chbBit6.checked = num & (1<<6);
        frm.chbBit5.checked = num & (1<<5);
        frm.chbBit4.checked = num & (1<<4);
        frm.chbBit3.checked = num & (1<<3);
        frm.chbBit2.checked = num & (1<<2);
        frm.chbBit1.checked = num & (1<<1);
        frm.chbBit0.checked = num & (1<<0);
      }
//-->
</script>


    <div id="main">
      <h1>Binary - 32-bit hex conversion</h1>
      <p>Converting set of 32 bits into 32-bit hexadecimal number and vice versa.
      </p>
      <p>
        My use case for this converter is editing dts files. While C/C++ allows to write numeric value in relatively clear way (bit sum with pre-defined values shifted
        to pre-defined positions) I don't think this is possible with dts and setting some value (especially multiple bits, spanning over two or more hex digits boundary) at e.g. bit offset 22 or checking if it is already set is error prone.
      </p>
      <form name="frmConvert" action="">
        <p><strong>Binary:</strong></p>
        <p>
          <table>
            <tr>
              <td>Bit #</td>
              <td>31</td>
              <td>30</td>
              <td>29</td>
              <td>28</td>
              <td>27</td>
              <td>26</td>
              <td>25</td>
              <td>24</td>
              <td>23</td>
              <td>22</td>
              <td>21</td>
              <td>20</td>
              <td>19</td>
              <td>18</td>
              <td>17</td>
              <td>16</td>
            </tr>
            <tr>
              <td>Value</td>
              <td><input type="checkbox" name="chbBit31" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit30" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit29" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit28" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit27" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit26" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit25" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit24" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit23" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit22" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit21" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit20" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit19" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit18" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit17" onchange="binChange()"></td>
              <td><input type="checkbox" name="chbBit16" onchange="binChange()"></td>
            </tr>
            <tr>
                <td>Bit #</td>
                <td>15</td>
                <td>14</td>
                <td>13</td>
                <td>12</td>
                <td>11</td>
                <td>10</td>
                <td>9</td>
                <td>8</td>
                <td>7</td>
                <td>6</td>
                <td>5</td>
                <td>4</td>
                <td>3</td>
                <td>2</td>
                <td>1</td>
                <td>0</td>
              </tr>
              <tr>
                <td>Value</td>
                <td><input type="checkbox" name="chbBit15" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit14" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit13" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit12" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit11" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit10" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit9" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit8" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit7" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit6" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit5" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit4" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit3" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit2" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit1" onchange="binChange()"></td>
                <td><input type="checkbox" name="chbBit0" onchange="binChange()"></td>
              </tr>            
          </table>
        </p>
        <p>
          <strong>Hex:</strong> <input type="text" name="hex" value="0x00000000" style="width: 150px; font-family: monospace; font-size: 150%" onchange="hexChange()" onkeyup="hexChange()">
        </p>
      </form>
    </div>


<div id="sidebar">
<h3>Sitemap</h3>

<ul id="tree0" class="tree">

    <li ><a>PROJECTS</a>
    <ul>
    <li><A HREF="../programator.htm" TARGET="_self">FLASH 49F programmer</A></li> 
    </ul>
    </li>

 
    <li><a>ONLINE TOOLS</a>
    <ul>
    <li><a href="./base64.htm" TARGET="_self">Base64 -&gt; HEX</A></li>
    <li><a href="./base32.htm" TARGET="_self">Base32 -&gt; HEX</a></li>
    <li><a href="./base32hex.htm" TARGET="_self">Base32hex -&gt; HEX</a></li>
    <li><a href="./ascii.htm" TARGET="_self">ASCII -&gt; HEX</a></li>
    <li><a href="./ascii_uN.htm" TARGET="_self">ASCII -&gt; u16/u32/u64 HEX</a></li>            
    <li><a href="./hex_to_base64.htm" TARGET="_self">HEX -&gt; Base64</a></li>
    <li><a href="./text_to_base64.htm" TARGET="_self">Text -&gt; Base64</a></li>
    <li><a href="./hex_to_base32.htm" TARGET="_self">HEX -&gt; Base32</a></li>
    <li><a href="./hex_to_base32hex.htm" TARGET="_self">HEX -&gt; Base32hex</a></li>
    <li><a href="./hex_to_ascii.htm" TARGET="_self">HEX -&gt; ASCII</a></li>
    <li><a href="./hex_to_dec.htm" TARGET="_self">HEX -&gt; DEC</a></li>	
    <li><a href="./dec_to_ascii.htm" TARGET="_self">DEC -&gt; ASCII</a></li>
    <li><a href="./bin_to_32bit_hex.htm" TARGET="_self">BIN &lt;-&gt; 32-bit hex</a></li>    
    <li><a href="./md5.htm" TARGET="_self">MD5 calculator</a></li>
    <li><a href="./sha1.htm" TARGET="_self">SHA1 calculator</a></li>    
    <li><a href="./regexp.htm" TARGET="_self">Regular exp.</a></li>
    <li><a href="./cpp_text_escape.htm" TARGET="_self">Text -&gt; Cpp</a></li>
    <li><a href="./cpp_unescape.htm" TARGET="_self">Cpp -&gt; text</a></li>
    <li><a href="./pascal_escape.htm" TARGET="_self">Text -&gt; Pascal</a></li>        
    <li><a href="./hex_to_file.htm" TARGET="_self">HEX -&gt; file</a></li>
    <li><a href="./file_to_hex.htm" TARGET="_self">File -&gt; HEX</a></li>
    <li><a href="./file_to_base64.htm" TARGET="_self">File -&gt; Base64</a></li>    
    <li><a href="./html_list_gen.htm" TARGET="_self">Text -&gt; HTML ul</a></li>
    <li><a href="./crc8.htm" TARGET="_self">CRC8</a></li>
    <li><a href="./wave_gen.htm" TARGET="_self">WAVE generator</a></li>
    <li><a href="./bin_decoder.htm" TARGET="_self">Bin decoder</a></li>
    <li><a href="./rc4.htm" TARGET="_self">RC4</a></li>          
    <li><a href="./xor.htm" TARGET="_self">XOR</a></li>
    <li><a href="./inv.htm" TARGET="_self">Inverting bits</a></li>
    <li><a href="./par_resistors.htm" TARGET="_self">Par. resistors search</a></li>
    <li><a href="./unique_str.htm" TARGET="_self">Deduplicate / sort</a></li>        
    <li><a href="./base64_to_PEM.htm" TARGET="_self">Base64 -&gt; PEM</a></li>
    <li><a href="./PEM_to_base64.htm" TARGET="_self">PEM -&gt; base64</a></li>
    <li><a href="./diskstats.htm" TARGET="_self">/proc/diskstats</a></li>    
    </ul>
    </li> 


    <li><A HREF="../contact2.htm" TARGET="_self">Contact</A></li></ul>
<script type="text/javascript">
//<!--
new tree("tree0");
//-->
</script>

<br>  
<br>  
<br>  





  <br>    

        
    
</div>


<div id="footer">




  
</div>


<br>
<div id="footer2"><p>      
      <!-- <font size="-2">&nbsp;"Cookie monsters": 5583818&nbsp;&nbsp;&nbsp;&nbsp;Parse time:&nbsp;0.000 s</font> -->
  </p>
	</div>
</div>
</body>
</html>

